/* eslint-disable import/no-anonymous-default-export */
import {addVip,addRights,delVip,delRights, list, rightsList,upload,vipLogs} from '../services/vipApi';



export default {
    state: {
        vipData: [],
        rightsData:[],
        img:'',
        vipLogsData:[]
    },
    effects: {
        async list(params) {
            const response = await list(params)
            if (response.code === 200) {
                this.saveData({
                    vipData: response.data,

                })
            }
            return response.data
        },

        async rightsList(params) {
            const response = await rightsList(params)
            if (response.code === 200) {
                this.saveData({
                    rightsData: response.data,
                    img:''

                })
            }
            return response.data
        },
        async vipLogList(params) {
            const response = await vipLogs(params)
            if (response.code === 200) {
                this.saveData({
                    vipLogsData: response.data,
                    vipData: [],
                    rightsData:[],
                    img:''
                })
            }
            return response.data
        },



        async addVip(params) {
            await addVip(params)
        },
        async addRights(params) {
            await addRights(params)
        },
        async delVip(params) {
            await delVip(params)
        },
        async delRights(params) {
            await delRights(params)
        },
        async upload(params) {
            const response = await upload(params)
            if (response.code === 200) {

                this.saveData({
                    img: response.data
                })

            }
            return response
        },


    },
    reducers: {
        saveData(state, paylode) {
            return {
                ...state,
                ...paylode,

            }
        },
        saveVipLogData(state, paylode) {
            return {
                ...state,
                ...paylode,

            }
        },
    }
}